package com.dps.recommend.layer.rank;

import com.dps.recommend.ann.LayerAnn;
import com.dps.recommend.beans.DpsRequest;
import com.dps.recommend.beans.ProcessInterface;
import com.dps.recommend.beans.RecItemDps;
import com.dps.recommend.enums.LayerEnum;
import com.dps.recommend.utils.DpsBaseService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 截取数量
 */
@Service
@LayerAnn(layer = LayerEnum.RANK)
class DpsRecNumRank extends DpsBaseService implements ProcessInterface {

    @Override
    public <R extends RecItemDps> List doProcess(DpsRequest dpsRequest, List<R> list) {
        String pageSize = (String) dpsRequest.getRoad().getProperties().getOrDefault("pageSize", String.valueOf(dpsRequest.getRequest().getPageSize()));
        List<R> recItemRes = list.stream().limit(Integer.valueOf(pageSize)).collect(Collectors.toList());
        return recItemRes;
    }
}
